package com.king01.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.king01.dao.StaffExDao;
import com.king01.entity.Staff;
import com.king01.entity.StaffEx;
import com.king01.service.StaffExSevice;
import com.king01.vo.OutlibraryVo;
import com.king01.vo.Result;
import com.king01.vo.StaffExVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Service
public class StaffExSeviceImpl implements StaffExSevice {
@Autowired
private StaffExDao stafftransferDao;
@Autowired
private HttpSession session;
    @Override
    public Result findAll(Integer current, Integer pageSize, StaffExVo staffExVo) {
        //mybatis-pageHelper插件
        PageHelper.startPage(current, pageSize);
        Staff attribute = (Staff)session.getAttribute("staff");
        staffExVo.setBranchid(attribute.getBranchid());

        List<StaffEx> all = stafftransferDao.findAll(staffExVo);
        PageInfo<StaffEx> pageInfo = new PageInfo<>(all);

        return new Result(200, "查询成功", pageInfo);


    }

    @Override
    public Result update1(StaffExVo staffExVo) {
        Staff attribute =(Staff) session.getAttribute("staff");
        Date date = new Date();
        staffExVo.setExtime(date);
        staffExVo.setExid(attribute.getStaffid());
        Integer integer = stafftransferDao.update1(staffExVo);
        return new Result(200, "成功", integer);
    }

    @Override
    public Result update2(StaffExVo staffExVo) {
        Staff attribute =(Staff) session.getAttribute("staff");
        Date date = new Date();
        staffExVo.setExtime(date);
        staffExVo.setExid(attribute.getStaffid());
        Integer integer = stafftransferDao.update2(staffExVo);
        return new Result(200, "成功", integer);
    }

    @Override
    public Result updateStaffBranchAndDept(StaffExVo staffExVo) {
        Integer integer = stafftransferDao.updateStaffBranchAndDept(staffExVo);
        if (integer>0){
            return new Result(200, "修改成功", null);
        }else {
            return new Result(500, "修改失败", null);

        }
    }

    @Override
    public Result findStaffByBranch(Integer branchid) {
        List<Staff> staffByBranch = stafftransferDao.findStaffByBranch(branchid);
        return new Result(200, "", staffByBranch);

    }
}
